/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package arimaa;

import java.awt.Color;
import java.awt.Graphics;
import java.util.ArrayList;
import javax.swing.JPanel;

public class PieceDisplayer extends JPanel{

    ArrayList<Piece> pieces = new ArrayList<Piece>();

    public PieceDisplayer(ArrayList<Piece> pieces) {
        this.pieces = pieces;
        setBackground(Color.getHSBColor(0.0f, 0.492f, 0.249f));
    }

    public void updatePieces(ArrayList<Piece> pieces) {
        this.pieces = pieces;
    }

    public Piece getPiece(int i) {
        return pieces.get(i);
    }

    @Override
    protected void paintComponent(Graphics g) {
        super.paintComponent(g);
        int width = this.getWidth();
        int height = this.getHeight();
        g.setColor(Color.white);
        g.drawLine(width/2, 0, width/2, height);
        for (int i = 0; i < 8; i++) {
            g.drawLine(0, i*height/8, width, i*height/8);
        }
        
        int current = 0;
        for (int i = 0; i < 2; i++) {
            for (int j = 0; j < 8; j++) {
                if(current < pieces.size()) {
                    pieces.get(current).paintSelf(g, i*width/2, j*height/8, width/2, height/8);
                }
                current++;
            }
        }
    }

    void remove(Piece selectedPiece) {
        pieces.remove(selectedPiece);
    }

    int getPiecesLeft() {
        return pieces.size();
    }
}
